<?php 
## include required files
/*******************************/
require_once '../../includefiles.php';
require_once '../../model/users.php';
require_once '../../model/email.php';
include_once("../../model/trade.php");
include_once("../../model/budget.php");
require_once "../../includes/classes/paging_htacess.php";
require_once '../../redirect.php';

## creating objects of required models
$userObj 		= new Model_Users();
$tradeObj = new Model_TRADE();
$budgetObj = new Model_Budget();

checkUserLogin();

if($_SESSION['user_type'] == '3')
{
	@header("location:".SITE_URL."/");
	exit;
}


$userId =$_SESSION['getbids_id'];

## When user wants to delete the testimonial
if($_GET['id1'] == 'delete' && $_GET['id2']!='')
{
	$PhotoID = base64_decode($_GET['id2']);	
	$userPhotoDetArray = $userObj->getUserPhotoDetailsByPhotoId($PhotoID);	
	@unlink('../../uploads/tradesmanjobs/'.$userPhotoDetArray['image']);
	
	$userObj->deleteWorkPhotoById($PhotoID);
	$_SESSION['msg'] = "<div class='success_msg'style='margin-top:5px;margin-bottom: 20px;'><span>Work photo deleted successfully !</span></div>";
	header("Location:".SITE_URL."/myaccount/myuploadedphoto");
	exit;
}




## for pagination
	$page = $_GET['id1'];
	if(!isset($_GET['id1']))
	$page = 1;
	else
	$page = $page;
	
## limit per pag 
$tetsimonialPerPage =10;
$StartRow = $tetsimonialPerPage  * ($page-1);
## Getting all myaccount from database according to user

if($_POST['search']!='' && $_POST['search']!='Title')
{
	$search = addslashes($_POST['search']); 
} 
elseif($_GET['id2']!='')
{
	$search =addslashes(base64_decode($_GET['id2'])); 
}
else {
	$search = '';
}
$smarty -> assign("search",stripslashes (stripslashes ($search)));


$imageArray  = $userObj->getAllWorkPhotoByUserID($userId,$search);
$totalCount        = count($imageArray);
$smarty -> assign("recordsFound",$totalCount);

$imageArray = $userObj->getAllWorkPhotoByUserID($userId,$search,$tetsimonialPerPage,$StartRow);
$show = 1;
$total_pages = ceil($totalCount / $tetsimonialPerPage);
	if($total_pages > 1)
	$smarty -> assign("showpgnation","yes");
	$showing    = !isset($_GET["id1"]) ? 1 : $page;
	
	## it shoould be file name 
	if($search!='')
		$firstlink  = base64_encode($search)."/myuploadedphoto/";
	else
		$firstlink  = "myuploadedphoto/";	
	
	$baselink   = $firstlink; 
	if($total_pages!=0)
		$pagenation = pagination($total_pages, $show, $showing, $firstlink, $baselink, "", "myaccount");
	$smarty -> assign("pagenation", $pagenation);
	$smarty -> assign("page", $page);
	
	//echo "<pre>"; print_r($imageArray);exit;
	$smarty->assign("imageArray", $imageArray);
	
/*===========================================================================*/
	$userDetArray = $userObj->getUserDetailsByUserId($userId);
	$smarty->assign("userDetArray", $userDetArray);	
	
/*===========================================================================*/	

$getallTradeJobType = $tradeObj->getAllJobTypeWithActiveStatus();
$smarty->assign("getallTradeJobType", $getallTradeJobType);	

$getallBudget = $budgetObj->getAllBudgetWithActiveStatus();
$smarty->assign("getallBudget", $getallBudget);	


if($_SESSION['msg']){
		$smarty->assign("msg", $_SESSION['msg']);
		unset($_SESSION['msg']);
}

$active ="myaccount";
$smarty->assign('active',$active);
$subactive ="myuploadedphoto";
$smarty->assign('subactive',$subactive);
$smarty->assign('mainmenu',"1");

$smarty->display(TEMPLATEDIR.'/modules/myaccount/myuploadedphoto.tpl');
unset($smarty);
?>
